package com.example.wangning.mycarofcountry.main;


import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TabHost;

import com.example.wangning.mycarofcountry.R;
import com.example.wangning.mycarofcountry.find.FindFragment;
import com.example.wangning.mycarofcountry.forum.ForumFragment;
import com.example.wangning.mycarofcountry.recommend.RecommendFragment;
import com.example.wangning.mycarofcountry.findcar.FindCarFragemnt;
import com.example.wangning.mycarofcountry.my.MyFragment;
import com.example.wangning.mycarofcountry.tool.DayNightMode;

public class MainActivity extends AppCompatActivity {
    private TabHost tabHost;
    private FragmentManager fragmentManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //在Activity开始初始化视图前去应用才能生效
        DayNightMode.onActivityCreateSetTheme(this);

        setContentView(R.layout.activity_main);
        tabHost = (TabHost) findViewById(android.R.id.tabhost);
        tabHost.setup();
        initView();
    }
    private void initView() {
        TabHost.TabSpec rdtabSpec = tabHost.newTabSpec("recommend");
        View recommendView = getLayoutInflater().inflate(R.layout.tab_recommend_item,null);
        rdtabSpec.setIndicator(recommendView);
        rdtabSpec.setContent(R.id.recommendView);
        tabHost.addTab(rdtabSpec);
        TabHost.TabSpec fmtabSpec = tabHost.newTabSpec("forum");
        View forumView = getLayoutInflater().inflate(R.layout.tab_forum_item,null);
        fmtabSpec.setIndicator(forumView);
        fmtabSpec.setContent(R.id.forumView);
        tabHost.addTab(fmtabSpec);
        TabHost.TabSpec frtabSpec = tabHost.newTabSpec("findcar");
        View findcarView = getLayoutInflater().inflate(R.layout.tab_findcar_item,null);
        frtabSpec.setIndicator(findcarView);
        frtabSpec.setContent(R.id.findCarView);
        tabHost.addTab(frtabSpec);
        TabHost.TabSpec fdtabSpec = tabHost.newTabSpec("find");
        View findView = getLayoutInflater().inflate(R.layout.tab_find_item,null);
        fdtabSpec.setIndicator(findView);
        fdtabSpec.setContent(R.id.findView);
        tabHost.addTab(fdtabSpec);
        TabHost.TabSpec mytabSpec = tabHost.newTabSpec("my");
        View myView = getLayoutInflater().inflate(R.layout.tab_my_item,null);
        mytabSpec.setIndicator(myView);
        mytabSpec.setContent(R.id.myView);
        tabHost.addTab(mytabSpec);
        fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.replace(R.id.recommendView,new RecommendFragment());
        fragmentTransaction.replace(R.id.forumView,new ForumFragment());
        fragmentTransaction.replace(R.id.findCarView,new FindCarFragemnt());
        fragmentTransaction.replace(R.id.findView,new FindFragment());
        fragmentTransaction.replace(R.id.myView,new MyFragment());
        fragmentTransaction.commit();
    }
}
